package com.cy.train.business.controller.admin;

import cn.hutool.core.util.ObjectUtil;
import com.cy.train.business.req.DailyTrainTicketQueryReq;
import com.cy.train.business.req.DailyTrainTicketSaveReq;
import com.cy.train.business.resp.DailyTrainTicketQueryResp;
import com.cy.train.business.service.DailyTrainTicketService;
import com.cy.train.common.resp.CommonResp;
import com.cy.train.common.resp.PageResp;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/daily-train-ticket")
public class DailyTrainTicketAdminController {
    @Autowired
    private DailyTrainTicketService dailyTrainTicketService;

    @PostMapping("/save")
    public CommonResp<Object> register(@Valid @RequestBody DailyTrainTicketSaveReq req) {
        dailyTrainTicketService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp> queryList(@Valid DailyTrainTicketQueryReq req) {
        if(ObjectUtil.isNull(req)) {
            req = new DailyTrainTicketQueryReq();
        }
        PageResp<DailyTrainTicketQueryResp> resp = dailyTrainTicketService.queryList(req);
        return new CommonResp<>(resp);
    }

    @GetMapping("/query-list-cache")
    public CommonResp<PageResp> queryListCache(@Valid DailyTrainTicketQueryReq req) {
        if(ObjectUtil.isNull(req)) {
            req = new DailyTrainTicketQueryReq();
        }
        PageResp<DailyTrainTicketQueryResp> resp = dailyTrainTicketService.queryListCache(req);
        return new CommonResp<>(resp);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        dailyTrainTicketService.delete(id);
        return new CommonResp<>();
    }
}